
package com.objetdirect.gwt.umldrawer.client;

import static com.objetdirect.gwt.umlapi.client.umlcomponents.DiagramType.CLASS;

import com.google.gwt.core.client.GWT;
//import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
//import com.google.gwt.uibinder.client.UiHandler;
//import com.google.gwt.user.client.DOM;
//import com.google.gwt.user.client.Element;
//import com.google.gwt.user.client.Window;
//import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.ResizeComposite;
import com.google.gwt.user.client.ui.Widget;
import com.objetdirect.gwt.umlapi.client.Drawer;
import com.objetdirect.gwt.umlapi.client.helpers.OptionsManager;
import com.objetdirect.gwt.umlapi.client.umlCanvas.UMLCanvas;
import com.objetdirect.gwt.umlapi.client.umlCanvas.UMLCanvasClassDiagram;

public class DrawerContainer extends ResizeComposite {

	private static DrawerContainerUiBinder uiBinder = GWT
			.create(DrawerContainerUiBinder.class);

	interface DrawerContainerUiBinder extends UiBinder<Widget, DrawerContainer> {
	}

//	@UiField
//	Button exportToUrl;
//
//	@UiField
//	Button clearUrl;
//
//	@UiField
//	Button exportToSvg;

	@UiField
	LayoutPanel drawerContainer;

	private UMLCanvas umlCanvas;

	private Drawer drawer;

	/**
	 * Create a default canvas for a class Diagram.
	 */
	public DrawerContainer() {
		initWidget(uiBinder.createAndBindUi(this));
		OptionsManager.set("DiagramType", CLASS.getIndex());
		umlCanvas = UMLCanvasClassDiagram.createUmlCanvas(CLASS);
		drawer = new Drawer(umlCanvas, CLASS);
		drawerContainer.add(drawer);
	}

	/**
	 * @return the umlCanvas
	 */
	public UMLCanvas getUmlCanvas() {
		return umlCanvas;
	}

	/**
	 * @return the drawer
	 */
	public Drawer getDrawer() {
		return drawer;
	}

	@Override
	public void onResize() {
		super.onResize();
	}

	@Override
	protected void onLoad() {
		super.onLoad();
	}

//	@UiHandler("exportToUrl")
//	void clickExportToUrl(ClickEvent event) {
//		HistoryManager.upgradeDiagramURL(umlCanvas.toUrl());
//	}
//
//	@UiHandler("clearUrl")
//	void clickClearUrl(ClickEvent event) {
//		HistoryManager.upgradeDiagramURL("");
//	}
//
//	@UiHandler("exportToSvg")
//	void clickExportToSvg(ClickEvent event) {
//		String svg = "<?xml version='1.0' standalone='no'?><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>";
//		// Session.getActiveCanvas().clearArrows(); //TODO
//		svg += DOM.getInnerHTML((Element) umlCanvas.getContainer().getElement()
//				.getFirstChildElement());
//		Window.open("data:image/xml+svg;charset=utf-8," + svg, "SVG export",
//				"top");
//		// Session.getActiveCanvas().makeArrows(); //TODO
//	}
}
